import configparser

import yagmail

config = configparser.ConfigParser()
config.read('config.ini', encoding='utf-8')
mail_conf = dict(config.items('mail'))


class Mail:

    def __init__(self, host, port, user, password, receiver):
        self.receiver = receiver
        self.yag = yagmail.SMTP(host=host, port=port, user=user, password=password)
        self.yag.set_logging(yagmail.logging.DEBUG, 'monitor.log')

    def send_mail(self, subject, contents):
        self.yag.send(to=self.receiver.split(', '), subject=subject, contents=contents)


if __name__ == '__main__':
    Mail(**mail_conf).send_mail('测试一下', '你好！')
